<!DOCTYPE html>
<html>
<head>
    <include file="Public:header" />
    <!-- jqgrid-->
    <link href="__ACSS__/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <!-- Data picker -->
    <link href="__ACSS__/plugins/datapicker/datepicker3.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox ">
                    <div class="ibox-content">
                    	<div class="ibox-search-box">
                    		<div class="row">
	                    		<div class="infont col-md-2">
									<select class="form-control" name="shop_id" datatype="*" id="shop_id" placeholder="配货店铺">
										<option value="" >请选择超市</option>
										<foreach name="shop_list" item="shop_list">
											<option value="<{$shop_list.id}>" ><{$shop_list.name}></option>
										</foreach>
									</select>
								</div>
								<div class="infont col-md-2">
		                    		<input type="text" name="name" class="form-control" placeholder="产品名称">
								</div>
								<div class="infont col-md-2">
									<select name="status" class="form-control" placeholder="配货状态">
										<option value="">请选择</option>
										<option value="0">未审核配货</option>
										<option value="1">已审核配货</option>
									</select>
								</div>
								<div class="input-daterange" id="datepicker">
									<div class="infont col-md-2">
			                    		<input type="text" name="ctime" class="form-control" readonly="readonly" value="" placeholder="配货时间">
									</div>
								</div>
	                    		<div class="infont col-md-2">
	                    			<button class="btn btn-success btn-block btn-ibox-search" type="button">搜索</button>
	                    		</div>
                    		</div>
                    	</div>
                        <div class="jqGrid_wrapper">
                            <table id="table_list"></table>
                            <div id="pager_list"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<!-- 全局js -->
<include file="Public:foot" />
<!-- jqGrid -->
<script src="__AJSPLUGINS__/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="__AJSPLUGINS__/jqgrid/jquery.jqGrid.min.js?0820"></script>
<!-- Page-Level Scripts -->
<!-- Data picker -->
<script src="__AJSPLUGINS__/datapicker/bootstrap-datepicker.js"></script>
<script>
$(document).ready(function () {
	var params = "?";
	//初始化
    $.jgrid.defaults.styleUI = 'Bootstrap';
    $("#table_list").jqGrid({
    	url : '__URL__/getAllDistributionData' + params,
    	datatype: "json",
        height: 580,
        autowidth: true,
        shrinkToFit: true,
        rowNum: 20,
        rowList: [20, 30, 50,100,200],
         colNames: ['ID','学校','楼号','店铺名称','产品名称','库存','规格库存','配货时间','配货状态'],
        colModel: [{name : 'id',index : 'id'},
					{name : 'school_name',index : 'school_name'},
					{name : 'floor_num',index : 'floor_num'},
					{name : 'shop_name',index : 'shop_name'},
					{name : 'name',index : 'name'},
					{name : 'num',index : 'num',formatter:function(cellvalue, options, rowObject){
						if(rowObject.attribute_values.length!=0){
							var attribute_values = rowObject.attribute_values;
							var num = 0;
							for(var i in attribute_values){
								num = num*1+attribute_values[i]['num']*1;

							}
							var content = '<span>'+ num+'</span>';
						}else{

							var content = '<span>+'+ rowObject.num+'</span>';
							

						}
						return content;

					}},
					{name : 'attribute',index : 'is_attr',formatter:function(cellvalue, options, rowObject){
						var attribute_values = rowObject.attribute_values;
						var content = "";
						for(var i in attribute_values){
							content += attribute_values[i]['attr_value_name']+':+'+ attribute_values[i]['num']+'<br>';

						}
						return content;
					}},
					{name : 'ctime',index : 'ctime'},
					{name : 'status',index : 'status',formatter : function(cellvalue, options, rowObject){
						if(rowObject.status==0){
							content = '待配货';
						}else{
							content = '已审核配货';
						}
						return content;
					}}
					
                  ],
        pager: "#pager_list",
        viewrecords: true,
        hidegrid: false,
        sortname: "id",
        sortorder: "desc"
    });
    
    
    //搜索
    $(".btn-ibox-search").click(function() {
    	result = getSearchParamByInput();
    	$("#table_list").jqGrid('setGridParam', {
    		page: 1,
    		url : '__URL__/getAllDistributionData' + result
    	}).trigger("reloadGrid");
    })
    //监控回车
    $(".ibox-search-box").find(":input").keydown(function(event) {
		if(event.keyCode == 13){
			$(".btn-ibox-search").trigger("click");
		}
	})
    
    //获取搜索条件（仅限封装简单条件）
    function getSearchParamByInput() {
    	var result = "";
    	$(".ibox-search-box").find(":input").each(function() {
    		if($(this).val() != "") {
    			if(result != "") {
    				result += "&";
    			}else{
    				result += "?";
    			}
    			result += $(this).attr("name") + "=" + $(this).val();
    		}
    	})
    	return result;
    }
	
    // 添加适配响应
    $(window).bind('resize', function () {
        var width = $('.jqGrid_wrapper').width();
        $('#table_list').setGridWidth(width);
    });
	
    //Data picker
    $('.input-daterange').datepicker({
        keyboardNavigation: false,
        forceParse: false,
        autoclose: true,
        todayHighlight: true
    });
});
</script>
</html>